const button = document.createElement('button');

button.textContent = '一键复制';

button.style.position = 'fixed';

button.style.top = '120px';

button.style.right = '20px';

button.style.zIndex = '9999';

button.style.padding = '10px';

button.style.backgroundColor = '#4CAF50';

button.style.color = 'white';

button.style.border = 'none';

button.style.borderRadius = '5px';

button.style.cursor = 'pointer';
function msg(t) { const e=document.createElement('div');e.textContent=t;e.style='position:fixed;top:100px;left:50%;transform:translateX(-50%);background:#333;color:#fff;padding:10px 20px;border-radius:4px;z-index:9999;';document.body.appendChild(e);setTimeout(()=>e.remove(),2000); }
// 添加点击事件处理

button.addEventListener('click', () => {
    // index_detail-item-first__IS2_h
// 这里需要确定要复制的元素，例如使用CSS选择器
const companyName = document.querySelector('.index_company-name__LqKlo > .index_name__dz4jY'); // 公司名字
const idVal = document.querySelector('.index_detail-item-first__IS2_h > div'); //统一社会信用代码
const callVal = document.getElementsByClassName('index_detail-tel__fgpsE')[0]; //手机号
const nameLabel = document.querySelector('.index_detail-box__bAJrG > .index_detail-label__oRf2J'); //法人代表人/经营者label
const nameVal = document.querySelector('.index_detail-box__bAJrG > .detailValue > .index_legalPersonName-wrap__d_ogh > a'); //法人代表
const emailVal = document.querySelector('.index_detail-email__B_1Tq'); //邮箱
const addressVal = document.querySelector('.index_address-flex__umT58 > span > span'); //地址
console.log('companyName',companyName)
console.log('idVal',idVal)
console.log('idVal.textContent',idVal.textContent)
console.log('callVal',callVal)
console.log('nameLabel',nameLabel)
console.log('nameLabel.textContent',nameLabel.textContent)
console.log('nameVal',nameVal)
console.log('nameVal.textContent',nameVal.textContent)
console.log('emailVal',emailVal)
console.log('addressVal',addressVal)
if (companyName) {
    const textToCopy1 = companyName?.textContent;
    const textToCopy2 = idVal?.textContent;
    const textToCopy3 = callVal?.textContent;
    const textToCopy4 = nameVal?.textContent;
    const textToCopy5 = addressVal?.textContent;
    // const textToCopy6 = nameLabel?.textContent;
    const textToCopy7 = addressVal?.textContent;
    let textToCopy=`被告：${textToCopy1||'-'}，${textToCopy2||'-'}，${nameLabel?.textContent}${nameVal?.textContent}，地址：${textToCopy7||'-'}，邮箱：${emailVal?.textContent||'-'}，电话：${callVal?.textContent||'-'}`;
    // 使用Clipboard API复制文本
    console.log('textToCopy',textToCopy)
    navigator.clipboard.writeText(textToCopy).then(() => {
    msg('复制成功');

}).catch(err => {

console.error('复制失败:', err);

});

} else {

alert('未找到目标行');

}

});

// 将按钮添加到页面

document.body.appendChild(button);
